package monte;

import java.util.ArrayList;

/**
 * 战斗类
 */
public class Battle {
    BattleResult battleResult;
    int teamAIndex;
    int teamBIndex;

    public Battle(int teamAIndex, int teamBIndex) {
        this.teamAIndex = teamAIndex;
        this.teamBIndex = teamBIndex;
    }

    /**
     * 战斗类的模拟
     *
     * @param teams 传入的队伍引用对象
     */
    public int simulate(ArrayList<Team> teams) {
        Team teamA = teams.get(teamAIndex);
        Team teamB = teams.get(teamBIndex);
        battleResult = new BattleResult(teamA, teamB);
        double thetaA = (Math.random() * 0.2) + 0.9;
        double thetaB = (Math.random() * 0.2) + 0.9;
        double valA = teamA.getPower() * thetaA;
        double valB = teamB.getPower() * thetaB;
        if (valA > valB) {
            battleResult.setWinner(teamA);
            return teamAIndex;
        } else {
            battleResult.setWinner(teamB);
            return teamBIndex;
        }
    }

    /**
     * 取得战斗的结果
     *
     * @return 战斗的结果
     */
    public BattleResult getBattleResult() {
        return battleResult;
    }

}
